<!--
 * @Description: 回弹养护作业
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 14:56:02
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main style="display:flex">
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px;" class="el-icon-arrow-down"></i>
              </span>
              <transition name="to"></transition>
              <span v-show="showCardNav">
                <i style="margin-right: 5px;" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="display: inline-block;margin-bottom: 10px;">
                  <span style="margin-right: 12px;">校验时间</span>
                  <el-date-picker v-model="value1" size="medium" type="datetimerange" unlink-panels start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </span>
                <span style="margin-left: 24px;">
                  <span style="margin-right: 12px;">工程名称</span>
                  <el-input v-model="tableParam.projectName" style="width: 200px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px;">
                  <span style="margin-right: 12px;">状态</span>
                  <el-select v-model="tableParam.maintenancestate" placeholder="请选择" style="width: 140px;">
                    <el-option label="全部" value=""></el-option>
                    <el-option label="待养护" :value="0"></el-option>
                    <el-option label="已养护" :value="0"></el-option>
                  </el-select>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <div class="card">
            <div class="card_nav">
              <div></div>
              <div>
                <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px;">
                  <el-link :underline="false">
                    <span class="el-icon--left">
                      <i class="iconfont iconicon_button_filtrate"></i>
                    </span>
                    筛选
                  </el-link>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(item, index) in table" :key="index">
                      <el-checkbox v-model="item.status">{{
                        item.label
                        }}</el-checkbox>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark">
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label =='操作'?'right':false">
                    <template slot-scope="scope">
                      <span v-if="item.label == '状态'">
                        <span v-if="scope.row.maintenancestate == 0" style="color:#969799;">待养护</span>
                        <span v-if="scope.row.maintenancestate == 1" style="color:#00A754;">已养护</span>
                      </span>
                      <span v-else-if="item.label == '操作'">
                        <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='YANGH'))!==-1" class="bottom_one" size="mini" @click="open('addDialog', scope.row)">养护</el-button>
                        <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='YANGHULS'))!==-1" class="bottom_one" size="mini" @click="open('Dialog3', scope.row)">养护历史</el-button>
                      </span>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 图片查看 -->
    <el-dialog v-dialogDrag :visible.sync="Dialog1" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">图片信息</span>
      <div class="dialoginfo">
        <div>
          <el-image v-for="(item, index) in arr1" :key="index" style="width: 200px; height:200px;margin:0 10px 10px 10px;border-radius: 4px;" :src="item" :preview-src-list="arr1" :z-index="10000"></el-image>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog1 = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 养护 -->
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="720px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">养护</span>
      <div class="dialoginfo" style="padding:0">
        <el-form ref="reffromDate" :rules="rules2" :model="fromDate" label-width="110px">
          <el-form-item prop="springbackMaintenanceID">
            <span slot="label" style="color:#FF0000;">养护措施</span>
            <el-select v-model="fromDate.maintenanceMeasureId" placeholder="请选择">
              <el-option v-for="(item, index) in code1" :key="index" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="code">
            <span slot="label">图片</span>
            <FileComponent fileCode="springbackFile" :files="files" @deleteFile="deleteFile" @uplodeSuccess="uplodeSuccess" />
          </el-form-item>
          <div>
            <el-form-item prop="remark">
              <span slot="label">备注</span>
              <el-input v-model="fromDate.remark" type="textarea" :rows="5" resize="none" placeholder="请输入" style="width:450px" clearable></el-input>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="addDialog = false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" @click="submit1()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 养护历史 -->
    <el-dialog v-dialogDrag :visible.sync="Dialog3" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">养护历史</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="arr3" tooltip-effect="dark">
          <el-table-column label="序号" align="center">
            <template slot-scope="scope">{{ scope.$index + 1 }}</template>
          </el-table-column>
          <el-table-column label="养护措施" align="center" prop="maintenanceMeasure"></el-table-column>
          <el-table-column label="图片" align="center">
            <template slot-scope="scope">
              <span class="table_link" @click="open('Dialog1', scope.row)">查看</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center" prop="remark"></el-table-column>
          <el-table-column label="养护人" align="center" prop="createUserName"></el-table-column>
          <el-table-column label="更新时间" align="center" prop="createTime" width="158"></el-table-column>
        </el-table>
        <div class="pagination">
          <div class="top_page_totle">总共{{ total2 }}条</div>
          <el-pagination :current-page.sync="from3.page" :page-size="from3.pageSize" layout="prev, pager, next, jumper" :total="total2" @current-change="getarr3()"></el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="Dialog3 = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import FileComponent from '@/components/File/fileComponent';
import { queryPage, queryPage1, saveOrUpdate } from "@/api/smart/soiltest/b.js";
import { getDicType } from "@/api/common.js";
import { Loading } from 'element-ui';
var loadingInstance;
export default {
  components: { FileComponent },
  mixins: [mixin],
  data() {
    return {
      /*表格增删改查及下载接口*/
      saveOrUpdate: saveOrUpdate,
      queryPage: queryPage,
      /*表格数据*/
      table: [
        { label: "回弹校验ID", width: "160", prop: "code", status: true },
        { label: "工程名称", width: "120", prop: "projectName", status: true },
        {
          label: "工程性质",
          width: "160",
          prop: "projectLocation",
          status: true,
        },
        { label: "浇筑部位", width: "120", prop: "pourPart", status: true },
        { label: "产品名", width: "160", prop: "productName", status: true },
        { label: "状态", width: "120", prop: "", status: true },
        { label: "提交时间", width: "160", prop: "updateTime", status: true },
        { label: "操作", width: "200", prop: "", status: true },
      ],
      pagesType: 0,
      /*添加表单数据*/
      Dialog1: false,
      addDialog: false,
      Dialog3: false,
      value1: [],

      /*养护*/
      fromDate: {
        springbackMaintenanceID: "",
        maintenanceMeasure: "",
        remark: "",
        path: ''
      },
      rules2: {
        maintenanceMeasureId: [
          { required: true, message: "请选择养护措施", trigger: "change" },
        ],
      },
      code1: [],

      /*养护历史*/
      from3: {
        page: 1,
        pageSize: 10,
      },
      total2: 0,
      arr3: [],
      /*查看图片*/
      arr1: [],
      files: [],
    };
  },
  created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = { ...this.tableParam, name: "", code: "" };
    getDicType({ code: "conservatMeasure" }).then((res) => {
      this.code1 = res.data.items;
    });

    this.gettableData();
  },
  watch: {
    value1() {
      if (this.value1) {
        this.tableParam.startTime = this.value1[0];
        this.tableParam.endTime = this.value1[1];
      } else {
        this.tableParam.startTime = ''
        this.tableParam.endTime = ''
      }
    },
  },
  methods: {
    /**
     * @Description: 删除附件
     * @Param: 
     * @Author: wangwangwang
     */
    deleteFile(index) {
      this.files.splice(index, 1);
    },
    /**
     * @Description: 上传成功
     * @Param: 
     * @Author: wangwangwang
     */
    uplodeSuccess(data) {
      this.files.push(data);
    },
    init() {
      /*重置数据*/
      this.value1 = []
      this.tableParam.projectName = "";
      this.tableParam.maintenancestate = "";
      this.gettableData();
    },
    getarr3() {
      queryPage1(this.from3).then((res) => {
        this.arr3 = res.data.data;
        this.total2 = res.data.totalRows;
        this.console(res.data);
      });
    },
    open1(low) {
      console.log(low);
      this.imgsDialog = true;
    },
    open(key, low) {
      this.low = low;
      if (key == "Dialog1") {
        this[key] = true;
        this.arr1 = JSON.parse(low.path).map(res => ('/file/' + res.fileUrl));
      }
      if (key == "addDialog") {
        this[key] = true;
        this.fromDate = this.$options.data().fromDate;
        this.fromDate.springbackMaintenanceID = low.id;
        this.files = []
        setTimeout(() => {
          this.$refs.reffromDate.clearValidate();
        }, 10);
      }
      if (key == "Dialog3") {
        this[key] = true;
        this.from3.springbackMaintenanceID = low.id;
        this.getarr3();
      }
    },
    submit1() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          _this.fromDate.maintenanceMeasure = _this.$fromatTable(
            _this.code1,
            _this.fromDate.maintenanceMeasureId,
            "id",
            "itemName"
          );
          _this.fromDate.path = JSON.stringify(_this.files)
          _this.submitFromDate();
        } else {
          return false;
        }
      });
    },
    before1(file) {
      loadingInstance = Loading.service();
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isJPG) {
        loadingInstance.close();
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        loadingInstance.close();
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },
};
</script>
<style lang="scss">
.soiltestDialog2_ng {
  display: flex;
  flex-wrap: wrap;
  width: 520px;
}
.soiltestDialog2 {
  padding: 10px 0 0 10px;
  position: relative;
  .el-icon-circle-close {
    cursor: pointer;
    z-index: 9;
    position: absolute;
    right: -8px;
    top: 0;
    font-size: 20px;
  }
  .el-icon-circle-close:hover {
    color: red;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 160px;
    height: 160px;
    line-height: 160px !important;
    text-align: center;
  }
  .avatar {
    width: 160px;
    height: 160px;
    display: block;
    overflow: hidden;
    border-radius: 6px;
  }
}
</style>
<style lang="scss" scoped>
.dialoginfo-title {
  display: flex;
  justify-content: space-between;
  padding: 10px 0 20px 0;
  font-weight: bold;
}
.el-input,
.el-select {
  width: 240px;
}
/*
 <el-link class="table_link" :underline="false">查看配合比</el-link>*/
.table_link {
  margin: 0 10px;
  color: $bg_color;
}

.table_link:hover {
  opacity: 0.8;
}
</style>
